<template>
  <div class="homeBox">
    <div class="left">
      <div class="leftNav">
        <el-menu
          :default-active="activeIndex"
          class="elMenu"
          background-color="#333"
          text-color="#B0B0B2"
          active-text-color="#fff"
          :unique-opened="true"
          router
          ref="elMenu"
          @select="menuSelect"
        >

          <el-submenu index="非叶子节点也需要index属性">
            <template slot="title">
              <i class="el-icon-star-off"></i>
              <span>前端三大框架</span>
            </template>
            <!-- 这个是没子节点的 没有子内容，直接用el-menu-item结构 -->
            <el-menu-item index="/vue">
              <i class="el-icon-star-off"></i>
              <span slot="title">vue页面</span>
            </el-menu-item>
            <el-menu-item index="/react">
              <i class="el-icon-star-off"></i>
              <span slot="title">react页面</span>
            </el-menu-item>
            <el-menu-item index="/angular">
              <i class="el-icon-pear"></i>
              <span slot="title">angular页面</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="非叶子节点也需要index属性哦">
            <template slot="title">
              <i class="el-icon-star-off"></i>
              <span>后端两大框架</span>
            </template>
            <el-menu-item index="/springBoot">
              <i class="el-icon-star-off"></i>
              <span slot="title">Spring Boot页面</span>
            </el-menu-item>

            <!-- 注意看这里有子节点的无子节点的html标签的区别 -->

            <!-- 这个是有子节点的 还有子内容，用el-submenu结构-->
            <el-submenu index="非叶子节点也需要index属性哈">
              <template slot="title">
                <i class="el-icon-star-off"></i>
                <span>Spring页面</span>
              </template>
              <el-menu-item index="/mysql">
                <i class="el-icon-star-off"></i>
                <span slot="title">MySql页面</span>
              </el-menu-item>
              <el-menu-item index="/redis">
                <i class="el-icon-star-off"></i>
                <span slot="title">Redis页面</span>
              </el-menu-item>
            </el-submenu>

            <!-- 这个是没子节点的 没有子内容，用el-menu-item结构 -->
            <el-menu-item index="/mybatis">
              <i class="el-icon-star-off"></i>
              <span slot="title">Mybatis页面</span>
            </el-menu-item>

          </el-submenu>

        </el-menu>
      </div>
    </div>
    <div class="right">
      <div class="rightTop">
        <el-button type="primary" plain @click="loginOut">登出</el-button>
      </div>
      <div class="rightBottom">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import myitem from "./components/myitem.vue";
export default {
  name: "Home",
  components: {
    myitem,
  },
  data() {
    return {
      activeIndex: this.$route.path,
      // 然后再通过权限管理页面，去添加或修改这个树结构，这样的话，前端就会呈现出来了
      menuArr: [
        {
          name: "前端三大框架",
          path: "前端三大框架",
          icon: "el-icon-star-off",
          children: [
            {
              name: "vue页面",
              path: "/vue",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "react页面",
              path: "/react",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "angular页面",
              path: "/angular",
              icon: "el-icon-star-off",
              children: [],
            },
          ],
        },
        {
          name: "后端两大框架",
          path: "后端两大框架",
          icon: "el-icon-star-off",
          children: [
            {
              name: "Spring Boot页面",
              path: "/springBoot",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "Spring页面",
              path: "Spring页面", // 有children，name和path就保持一致；没有的话，path的值就是路由表中用到的，不保持一致也行，因为不会用到
              icon: "el-icon-star-off",
              children: [
                {
                  name: "MySql页面",
                  path: "/mysql",
                  icon: "el-icon-star-off",
                  children: [],
                },
                {
                  name: "Redis页面",
                  path: "/redis",
                  icon: "el-icon-star-off",
                  children: [],
                },
              ],
            },
            {
              name: "Mybatis页面",
              path: "/mybatis",
              icon: "el-icon-star-off",
              children: [],
            },
          ],
        },
      ],
    };
  },
  mounted() {},
  methods: {
    menuSelect(index) {
      this.activeIndex = index;
    },
    loginOut() {
      this.$router.push({
        path: "/login",
      });
      sessionStorage.removeItem("token");
    },
  },
};
</script>

<style lang="less" scoped>
.homeBox {
  width: 100%;
  height: 100%;
  display: flex;
  .left {
    width: 216px;
    height: 100%;
    .leftNav {
      width: 216px;
      height: 100%;
      // background-color: pink;
      .elMenu {
        width: 100%;
        height: 100%;
      }
      /deep/ .el-menu-item.is-active {
        background-color: #478ce9 !important;
        font-weight: bold;
      }
    }
  }
  .right {
    width: calc(100% - 216px);
    height: 100%;
    .rightTop {
      width: 100%;
      height: 60px;
      background-color: rgb(161, 238, 208);
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .rightBottom {
      width: 100%;
      height: calc(100% - 60px);
    }
  }
}
</style>
